﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using Infrastructure.CurrentData;
using Microsoft.Practices.Composite.Modularity;

namespace UI
{
    /// <summary>
    /// Interaction logic for About.xaml
    /// </summary>
    public partial class About : Window
    {
        public About()
        {
            InitializeComponent();

            version.Text = ReadVersion();
            Modules.ItemsSource = ReadLoadedModules();
            Modules.DisplayMemberPath = "ModuleName";
        }

        private void licenseLink_MouseUp(object sender, MouseButtonEventArgs e)
        {
            StartLink("http://bookcataloger.codeplex.com/license");
        }

        private void developerLink_MouseUp(object sender, MouseButtonEventArgs e)
        {
            StartLink("http://techiethings.blogspot.com/");
        }

        private void homepageLink_MouseUp(object sender, MouseButtonEventArgs e)
        {
            StartLink("http://bookcataloger.codeplex.com/");
        }

        static void StartLink(string link)
        {
            System.Diagnostics.Process.Start(link);
        }




        string ReadVersion()
        {
            var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            return string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);
        }

        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private IEnumerable<ModuleInfo> ReadLoadedModules()
        {
            var catalog = Current.Container.Resolve<Microsoft.Practices.Composite.Modularity.IModuleCatalog>();
            foreach (var module in catalog.Modules)
            {
                if(module.State == ModuleState.Initialized)
                {
                    yield return module;
                }
            }
        }

    }
}
